﻿using System;
using System.Collections.Generic;
using System.IO;
using ProjScan.Modules;
using ProjScan.RecordManager.AssetData;
using ProjScan.Tools;
using UnityEditor;
using UnityEngine;

namespace ProjScan.RecordManager
{
	// Token: 0x02000276 RID: 630
	internal abstract class ComponentRecordManager<T1, T2> : RecordManagerBase<T2> where T1 : Component where T2 : ComponentAssetData<T1>
	{
		// Token: 0x060010CE RID: 4302 RVA: 0x0004DB74 File Offset: 0x0004BD74
		public override void PrepareAssets()
		{
			this.datas = new List<T2>();
			int num = AssetPathManager.Instance.prefabPathList.Length;
			for (int i = 0; i < num; i++)
			{
				bool isEditor = Singleton<ScanInfo>.Instance.isEditor;
				if (isEditor)
				{
					EditorUtility.DisplayProgressBar("Proj Scan [" + this.TableTag + "]", string.Concat(new string[]
					{
						"Preparing ",
						this.TableTag,
						"(",
						this.datas.Count.ToString(),
						")..."
					}), (float)i * 1f / (float)num);
				}
				bool flag = i % 100 == 0;
				if (flag)
				{
					ToolsHelper.GC();
				}
				string text = AssetPathManager.Instance.prefabPathList[i];
				this.ActiveAllRecord();
				bool flag2 = this.CheckAssetPathRules(text);
				if (flag2)
				{
					GameObject gameObject = AssetDatabase.LoadAssetAtPath(text, typeof(GameObject)) as GameObject;
					bool flag3 = gameObject != null;
					if (flag3)
					{
						int id = AssetPathManager.Instance.GetID(Path.GetDirectoryName(text));
						T1[] componentsInChildren = gameObject.GetComponentsInChildren<T1>(true);
						bool flag4 = componentsInChildren != null && componentsInChildren.Length != 0;
						if (flag4)
						{
							foreach (T1 t in componentsInChildren)
							{
								try
								{
									bool flag5 = t != null && t.gameObject != null;
									if (flag5)
									{
										string fullObjectPath = ToolsHelper.GetFullObjectPath(Path.GetFileName(text), t.gameObject);
										T2 t2 = this.CreateAssetData(id, t, fullObjectPath);
										t2.id = this.datas.Count;
										this.ValidateAsset(t2);
										t2.Reset();
										this.datas.Add(t2);
										bool flag6 = this.datas.Count % 100 == 0;
										if (flag6)
										{
											ToolsHelper.GC();
										}
									}
								}
								catch (Exception ex)
								{
									ScanLog.Instance.LogInfo(ScanLog.LogLevel.EXCEPTION, Module.CS_Check, this.TableTag, string.Concat(new string[]
									{
										(ex.GetType() == null) ? null : ex.GetType().ToString(),
										"\n",
										ex.Message,
										"\n",
										ex.StackTrace
									}));
								}
							}
						}
					}
				}
			}
		}

		// Token: 0x060010CF RID: 4303
		public abstract T2 CreateAssetData(int directoryId, T1 component, string assetName);
	}
}
